#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from datetime import datetime
from email.policy import default
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime, Enum
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.mysql import INTEGER
from models.reservation import Reservation
from models.user import User
from db.database import Base
from common.utils import formatter


class Participant(Base):
    __tablename__ = 'participant'

    participant_id = Column(INTEGER(11), primary_key=True)
    reservation_id = Column(ForeignKey('reservation.reservation_id', ondelete='CASCADE'), nullable=False, index=True)
    user_id = Column(ForeignKey('user.user_id', ondelete='CASCADE'), nullable=False, index=True)
    check_in = Column(DateTime)
    check_out = Column(DateTime)
    status = Column(String(255))

    reservation = relationship('Reservation')
    user = relationship('User')

    def __init__(self, reservation_id, user_id):
        self.reservation_id = reservation_id
        self.user_id = user_id

    def __repr__(self):
        return 'Participant:%s' % self.name

    def to_dict(self):
        new_dict = {}
        for c in self.__table__.columns:
            new_dict[formatter(c.name)] = getattr(self, c.name, None)
        return new_dict
